package cn.enited.devtools.apiaggregator.utils;

import cn.enited.devtools.apiaggregator.consts.ErrorCode;
import cn.enited.devtools.apiaggregator.dto.*;
import org.springframework.data.domain.Page;

import java.util.List;
import java.util.Map;
import java.util.Set;

public final class ActionUtil {

    public static ActionResult success() {
        return ActionResult.of(ErrorCode.SUCCESS);
    }

    public static <T> PageActionResult<T> pageResult(Page<T> page) {
        return PageActionResult.of(ErrorCode.SUCCESS.code(), ErrorCode.SUCCESS.message(), page);
    }

    public static <T> SetActionResult<T> setResult(Set<T> set) {
        return SetActionResult.of(ErrorCode.SUCCESS.code(), ErrorCode.SUCCESS.message(), set);
    }

    public static <K, V> MapActionResult<K, V> mapResult(Map<K, V> map) {
        return MapActionResult.of(ErrorCode.SUCCESS.code(), ErrorCode.SUCCESS.message(), map);
    }

    public static <T> ListActionResult<T> listResult(List<T> list) {
        return ListActionResult.of(ErrorCode.SUCCESS.code(), ErrorCode.SUCCESS.message(), list);
    }

    public static <T> ObjectActionResult<T> objectResult(T object) {
        return ObjectActionResult.of(ErrorCode.SUCCESS.code(), ErrorCode.SUCCESS.message(), object);
    }

    public static ActionResult error() {
        return ActionResult.of(ErrorCode.ERROR);
    }

    public static ActionResult error(int code, String message) {
        return ActionResult.of(code, message);
    }

    public static ActionResult error(ErrorCode errorCode) {
        return ActionResult.of(errorCode);
    }
}
